/**
 * 添加className 
 */
export function addClass(el,className){
     if(hasClass(el,className)){
         return
     }
     let newName=el.className.split(' ')
     newName.push(className)
     el.className=newName.join(' ')
}

function hasClass(el,className){
    let reg=new RegExp('(^|\\s)'+className+'(\\s|$)')
    
    return reg.test(el.className)
}

/**
 * 获取dom的 自定义属性值
 */
export function getData(el,name,val){
    const pro='data-'
    name=pro+name
    if(val){
        return el.setAttribute(name,value)
    }
    else{
        //  console.log(el.getAttribute(name))
         return el.getAttribute(name)
    }
}

let elementStyle = document.createElement('div').style

let vendor = (() => {
  let transformNames = {
    webkit: 'webkitTransform',
    Moz: 'MozTransform',
    O: 'OTransform',
    ms: 'msTransform',
    standard: 'transform'
  }

  for (let key in transformNames) {
    if (elementStyle[transformNames[key]] !== undefined) {
      return key
    }
  }

  return false
})()

export function prefixStyle(style) {
  if (vendor === false) {
    return false
  }

  if (vendor === 'standard') {
    return style
  }

  return vendor + style.charAt(0).toUpperCase() + style.substr(1)
}
